<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script>
    //累加
    // function getSum(num) {
    //   if (num == 1) {
    //     return 1;
    //   }
    //   return num + getSum(num - 1);
    // }

    // console.log(getSum(100));

    //计算各个位数上的数字和    123   ===》   6
    // let i = 0;
    function getEvery(num) {
      if (num < 10) {    //  num <= 0  要多算一次，没有这个好
        return num;
      }
      // i ++; 计算循环次数 
      return (num%10) + getEvery(parseInt(num/10));
    }
    console.log(getEvery(123));
    // console.log(i);
  </script>
</body>
</html>